package org.yx.service.sres.update_group_info;

import org.yx.exception.BizException;
import org.yx.models.SResGrpDef;
import org.yx.utils.BaseService;
import org.yx.utils.FieldMap;

import com.xiaoleilu.hutool.util.StrUtil;

/**
 * 修改设备资源组
 * @author zxw
 * @since 2022/04/13
**/
public class SresUpdateGroupInfoService extends BaseService {
	public SresUpdateGroupInfoOut updateGroupInfo(SresUpdateGroupInfoIn in) throws Exception {
		if (in.getGroup() == null) {
			throw new BizException("SYS-0004", "请求的参数${parameter}要求不能为空。", FieldMap.of("parameter", "group"));
		}
		if (StrUtil.isBlank(in.getGroup().getGroupCode())) {
			throw new BizException("SYS-0004", "请求的参数${parameter}要求不能为空。", FieldMap.of("parameter", "group.groupCode"));
		}
		
		SResGrpDef group = selectOneLocked(SResGrpDef.class, in.getUserOrgCode(), in.getGroup().getGroupCode());
		if (group == null || "D".equals(group.getGroupStatus())) {
			throw new BizException("BAS-0008", "数据不存在或已被删除。");
		}
		
		copyProperties(in.getGroup(), group);
		
		update(group);
		
		SresUpdateGroupInfoOut out = new SresUpdateGroupInfoOut();

		return out;
	}
}